<link rel="stylesheet" href="__STATIC__/addon/file/Huploadify.css" />
<script src="__STATIC__/addon/file/jquery.Huploadify.js"></script>


<input type="hidden" name="{$addons_data['name']}" id="{$addons_data['name']}" value="{$addons_data['value']}"/>
<div class="upload-img-box{$addons_data['name']} clearfix">
    {notempty name="$info[$addons_data['name']]"}
        {assign name="file_ids_list" value="$info[$addons_data['name']]|str2arr" /}
        {volist name="file_ids_list" id='vo'}
            <div class="upload-pre-file" style="float:left; margin: 10px;">
                <a target="_blank" href="{$vo|default='0'|get_file_url=$addons_data.addons_model}">
                    {$info[$addons_data['name']]|default=''|get_file_url}
                </a>
                <span style="cursor:pointer; color:red;" class="pic_del"  onclick="picDel{$addons_data.name}(this, {$vo})" >
                    <img src="__STATIC__/addon/file/uploadify-cancel.png" />
                </span>
            </div>
        {/volist}
    {/notempty}
</div>
<div id="upload_pictures_{$addons_data['name']}"></div>
<script type="text/javascript">
    
    var maxwidth = "{$addons_config['maxwidth']}";
    var height = "{$addons_config['height']}";

    $("#upload_pictures_{$addons_data['name']}").Huploadify({
        auto: true,
        height          : 30,
        fileObjName     : "file",
        buttonText      : "上传文件",
        uploader        : "{$addons_config['upload_url']}",
        width         : 120,
        removeTimeout	  : 1,
        fileSizeLimit:"{$addons_config['max_size']}",
        fileTypeExts	  : "{$addons_config['allow_postfix']}",
        onUploadComplete : uploadFile{$addons_data.name}
    });
    function uploadFile{$addons_data.name}(file, data){
        var data = $.parseJSON(data);
        var addons_name = "{$addons_data.name}";
        var file_ids = $("#" + addons_name).val();
        var add_id = data.id;
        if(file_ids){
            var lastChar = file_ids.charAt(file_ids.length - 1);
            if(lastChar != ','){
                add_id = file_ids + ',' + add_id;
            }
        }
        $("#" + addons_name).val(add_id);
        
        //var src = '/upload/picture/' + data.path;
        var src ='__STATIC__/upload/file/' + data.path;
        var src =src.replace(/\/static/g, '');
        console.log(src);
        var addHtml='' +
            '<div class="upload-pre-file" style="float:left; margin: 10px;">' +
            '<a target="_blank" href="'+src+'"> ' + src + ' <a>' +
            '<span style="cursor:pointer; color:red;" class="pic_del"  onclick="picDel{$addons_data.name}(this,'+data.id+')" >' +
            '<img src="__STATIC__/addon/file/uploadify-cancel.png" />' +
            '</span>' +
            '</div>';

        $(".upload-img-box" + addons_name).prepend(addHtml);
    }

    //删除函数
    function picDel{$addons_data.name}(obj, pic_id)
    {
        var addons_name = "{$addons_data.name}";
        var file_ids = $("#" + addons_name).val();
        if(file_ids.indexOf(",") > 0)
        {
            file_ids.indexOf(pic_id) == 0 ? file_ids = file_ids.replace(pic_id + ',', '') : file_ids = file_ids.replace(',' + pic_id, '');
            $("#" + addons_name).val(file_ids);
        }else{
            $("#" + addons_name).val('');
        }
        $(obj).parents('.upload-pre-file').remove();
    }
</script>